home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-11 | 2.0 KB | 84 lines | [TEXT/PRLG] |
- %Some standard benchmarks
-
- nreverse([X|L0],L) :- nreverse(L0,L1),concatenate(L1,[X],L).
- nreverse([],[]).
-
- concatenate([X|L1],L,[X|L2]) :- concatenate(L1,L,L2).
- concatenate([],L,L).
-
- list30([1,2,3,4,5,6,7,8,9,10,11,
- 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]).
-
- times10(((((((((x*x)*x)*x)*x)*x)*x)*x)*x)*x).
- divide10(((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x).
- log10(log(log(log(log(log(log(log(log(log(log(x))))))))))).
- ops8((x+1)*(x^2+2)*(x^3+3)).
-
- myRepeat(0,X) :- !.
- myRepeat(Count,Procedure) :-
- callAndFail(Procedure),
- NewCount is Count-1,!,
- myRepeat(NewCount,Procedure).
-
- dummyRepeat(0,X) :- !.
- dummyRepeat(Count,Procedure) :-
- dummyCallAndFail(Procedure),
- NewCount is Count-1,
- !,
- dummyRepeat(NewCount,Procedure).
- dummyCallAndFail(X) :- dummyDoOnce(X),fail.
- dummyCallAndFail(_).
-
- dummyDoOnce(X) :- call(module(X)),!. %i.e. a do-nothing call
-
- callAndFail(X) :- doOnce(X),fail.
- callAndFail(_).
-
- doOnce(X) :- call(X),!.
-
- time(Count,Procedure) :-
- nonvar(Procedure),
- S is cputime,
- myRepeat(Count,Procedure),
- T is cputime,
- dummyRepeat(Count,Procedure),
- Ctime is cputime-T,
- !,
- Etime is T-S,
- Atime is Etime-Ctime,
- telling(CurrentOutput),
- tell(user),
- write('Elapsed time: '),
- write(Atime),write(' mS'),
- tell(CurrentOutput).
-
- d(U+V,X,DU+DV) :- !, d(U,X,DU),d(V,X,DV).
- d(U-V,X,DU-DV) :- !, d(U,X,DU),d(V,X,DV).
- d(U*V,X,DU*V+U*DV) :- !,d(U,X,DU),d(V,X,DV).
- d(U/V,X,(DU*V-U*DV)/V^2) :- !,d(U,X,DU),d(V,X,DV).
- d(U^N,X,DU*N*U^N1) :- integer(N),N1 is N-1,d(U,X,DU).
- d(-U,X,-DU) :- !,d(U,X,DU).
- d(exp(U),X,exp(U)*DU) :- !,d(U,X,DU).
- d(log(U),X,DU/U) :- !,d(U,X,DU).
- d(X,X,1) :- !.
- d(C,X,0).
-
- list50(
- [27,74,17,33,94,18,46,83,65,2,
- 32,53,28,85,99,47,28,82,6,11,
- 55,29,39,81,90,37,10,0,66,51,
- 7,21,85,27,31,63,75,4,95,99,
- 11,28,61,74,18,92,40,53,59,8]).
-
- qsort([X|L],R,R0) :-
- partition(L,X,L1,L2),
- qsort(L2,R1,R0),
- qsort(L1,R,[X|R1]).
- qsort([],R,R).
-
- partition([X|L],Y,[X|L1],L2) :- X=<Y,!,
- partition(L,Y,L1,L2).
- partition([X|L],Y,L1,[X|L2]) :-
- partition(L,Y,L1,L2).
- partition([],_,[],[]).
-